package com.example.fragment;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

public class SettingFragment extends Fragment implements View.OnClickListener {

    private ImageView mIvGremSet, mIvPeopleSet, mIvSystemSet;
    private View view;

    private LinearLayout ll;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        /**
         * 这里主要初始化一些在Fragment需使用和持久化的必要组件
         */
        super.onCreate(savedInstanceState);
    }



    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        /**
         * 使用inflate()方法加载一个自定义的layout布局，该布局是Fragment的跟布局view
         * inflate()方法的3个参数
         * 1.想要加载的layout Resource Id
         * 2.加载layoutde父ViewGroup ，目的是将layout挂靠到container上
         * 3.布尔值，指示是否将layout附着到VieGroup上，这里一般指定false
         * 因为layout已经附着到container上，若为true，系统将为layout新建一个ViewGroupzuop作为对象，多余
         */
        View inView = inflater.inflate(R.layout.activity_setting_fragment, container, false);

        /**
         * 这里主要是初始化layout中的控件对象
         */
        return inView;
    }

//    @Override
//    protected View initView() {
//        if (view == null) {
//            view = View.inflate(myActivity, R.layout.activity_setting_fragment, null);
//            mIvGremSet = view.findViewById(R.id.iv_grem_set);
//            mIvPeopleSet = view.findViewById(R.id.iv_people_set);
//            mIvPeopleSet = view.findViewById(R.id.iv_system_set);
//            mIvGremSet.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//
//                }
//            });
//            mIvPeopleSet.setOnClickListener(this);
//            mIvSystemSet.setOnClickListener(this);
//        }
//        return view;
//    }


    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mIvGremSet = getActivity().findViewById(R.id.iv_grem_set);
        mIvPeopleSet = getActivity().findViewById(R.id.iv_people_set);
        mIvSystemSet = getActivity().findViewById(R.id.iv_system_set);
        mIvGremSet.setOnClickListener(this);
        mIvPeopleSet.setOnClickListener(this);
        mIvSystemSet.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        MainActivity myactivity = (MainActivity) getActivity();
        switch (v.getId()) {
            case R.id.iv_grem_set:
                myactivity.initGrameSettingFragment();
                break;
            case R.id.iv_people_set:
                myactivity.initPeopleSettingFragment();
                break;
            case R.id.iv_system_set:
                myactivity.initSystemFragment();
                break;
            default:
                break;
        }
    }
}
